<template>
	<view v-if="cart.length !== 0" class="cart_container">
		<my-address></my-address>
		<view class="cart_title">
			<uni-icons type="shop" size="18"></uni-icons>
			<text class="cart_title__text">购物车</text>
		</view>
		<uni-swipe-action>
			<block class="cart_goods__container" v-for="(goods, index) in cart" :key="index">
				<uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(goods)">
					<my-goods 
						:goods="goods"
						:showRadioFlag="true"
						:showNumberFlag="true"
						@radioChange="raddioChanggeHandler"
						@numChange="numChangeHandler"
						></my-goods>
					</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		<view class="cart_settle__container">
			<my-settle></my-settle>
		</view>
	</view>
	
	<view v-else class="empty_cart">
		<image class="empty_cart__img" src="../../static/assets/image/cart_empty.png"></image>
		<text class="empty_cart__text">空空如也哦~</text>
	</view>
</template>

<script>
import badgeMix from '@/mixins/tabbar-badge'
import { mapState, mapMutations } from 'vuex'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				options: [{
				  text: '删除', // 显示的文本内容
				  style: {
				    backgroundColor: '#C00000' // 按钮的背景颜色
				  }
				}],
			};
		},
		
		computed: {
			...mapState('my_cart', ['cart']),
		},
		
		methods: {
			...mapMutations('my_cart', ['updateGoodsState', 'updateGoodsCount', 'removeGoodsById']),
			//商品勾选状态更新
			raddioChanggeHandler(goods) {
				this.updateGoodsState(goods);
			},
			//商品数量更新
			numChangeHandler(goods) {
				this.updateGoodsCount(goods);
			},
			
			swipeActionClickHandler(goods) {
			  console.log(goods)
			},
			
			swipeActionClickHandler(goods) {
				this.removeGoodsById(goods.goods_id);
			},
		},
	}
</script>

<style lang="scss">
.cart_container {
	margin-bottom: 100rpx;
	.cart_title {
		height: 80rpx;
		display: flex;
		align-items: center;
		border-top: 1px solid #f0f0f0;
		border-bottom: 1px solid #f0f0f0;
		.cart_title__text {
			margin-left: 10px;
		}
	}
}
.empty_cart {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding-top: 150px;
	.empty_cart__img {
		 width: 100%;
		height: 380rpx;
	}
	.empty_cart__text {
		font-size: 12px;
		color: gray;
		margin-top: 15px;
	}
}
</style>
